//
// Snake.hh for nibbler in /home/lefebv_w//workspace/cpp/nibbler/googleCode
// 
// Made by damien lefebvre
// Login   <lefebv_w@epitech.net>
// 
// Started on  Fri Mar 15 20:56:56 2013 damien lefebvre
// Last update Sun Mar 24 18:09:56 2013 damien lefebvre
//

#ifndef		__SNAKE_HH__
#define		__SNAKE_HH__

#include	<string>
#include	<vector>
#include	<list>
#include	<iostream>

#include	"header.hh"
#include	"IGraphicLibrary.hh"
#include	"Case.hh"

class		Snake
{
  class		PartOfSnake
  {
  private :
    unsigned int			m_pos_x;
    unsigned int			m_pos_y;
    IGraphicLibrary::e_TypeOfCase	m_type;
    IGraphicLibrary::e_Direction	m_direction;
    IGraphicLibrary::e_ListOfImage	m_img;
    
  public :
    PartOfSnake(unsigned int pos_x, unsigned int pos_y, IGraphicLibrary::e_TypeOfCase type, IGraphicLibrary::e_ListOfImage img, IGraphicLibrary::e_Direction dir);

    void		move(unsigned int new_pos_x, unsigned int new_pos_y, IGraphicLibrary::e_Direction dir);
    unsigned int			getPosX(void) const;
    unsigned int			getPosY(void) const;
    IGraphicLibrary::e_Direction	getDirection(void) const;
    IGraphicLibrary::e_ListOfImage	getImage(void) const;
    void				draw(IGraphicLibrary & graph) const;
    void				setImage(IGraphicLibrary::e_ListOfImage img);
    void				setDirection(IGraphicLibrary::e_Direction dir);
  };


private :
  unsigned int				m_nbmove;
  unsigned int				m_pos_x;
  unsigned int				m_pos_y;
  t_frame				m_lastmove;
  IGraphicLibrary::e_Direction		m_direction;
  unsigned int				m_partToAdd;
  IGraphicLibrary::e_Direction		m_olddirection;
  std::vector<PartOfSnake *>		m_body;

public :
  Snake(unsigned int pos_x, unsigned int pos_y, unsigned int nbOfPart);
  ~Snake(void);

  void		setDirection(IGraphicLibrary::e_Direction d);
  bool		addPart(std::vector< std::vector<Case *> > const & map, unsigned int nbOfPart = 0);
  void		move(t_frame frame, t_frame vitesse, std::vector< std::vector<Case *> > const & map);
  bool		checkEndOfGame(std::vector< std::vector<Case *> > const & map) const;
  void		draw(IGraphicLibrary & graph) const;
  bool		checkIntersection(unsigned int pos_x, unsigned int pos_y) const;
  void		newSnake(unsigned int pos_x, unsigned int pos_y, unsigned int nbOfPart);

  unsigned int	getPosX(void) const;
  unsigned int	getPosY(void) const;
  t_frame      	getLastMove(void) const;
  
private :
  void		getNewPos(unsigned int & pos_x, unsigned int & pos_y, IGraphicLibrary::e_Direction direction, bool part = true);
};

#endif
